package com.xxx.blog.controller;


import com.xxx.blog.entity.Books;
import com.xxx.blog.service.BooksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author WangXJ
 * @since 2021-08-08
 */
@ResponseBody
@RestController
@RequestMapping("/blog/books")
public class BooksController {

    @Autowired
    BooksService booksService;

    @GetMapping("/showAllBook")
    public List showAllBook() {
        return booksService.showAll();
    }

    @GetMapping("/findNewBook")
    public List findNewBook() {
        return booksService.findNewBook();
    }

    @RequestMapping("/findNewByType/{currentPage}/{size}/{type}")
    public List findNewByType(@PathVariable("currentPage") int currentPage,
                              @PathVariable("size") int size,
                              @PathVariable("type") int type){
        return booksService.findNewByType(currentPage,size,type);
    }

    @RequestMapping("/findAllByType/{currentPage}/{size}/{type}")
    public Map findAllByType(@PathVariable("currentPage") int currentPage,
                             @PathVariable("size") int size,
                             @PathVariable("type") int type) {
        return booksService.findAllByType(currentPage,size,type);
    }

    @RequestMapping("/findBookById/{bookId}")
    public Books findBookById(@PathVariable("bookId") int bookId) {
        return booksService.findBookById(bookId);
    }

    @RequestMapping("/findBookByName/{bName}")
    public List findBookByName(@PathVariable("bName") String bName) {
        return booksService.findBookByName(bName);
    }
}

